﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ChairtyBank.DAL;

namespace ChairtyBank
{
    public partial class CustomerSearchForm : Form
    {
        public Int32 currentForm;

        public CustomerSearchForm()
        {
            InitializeComponent();
        }

        private void customerDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1 && !customerDataGrid.Rows[e.RowIndex].IsNewRow)
            {
                string customerID = customerDataGrid.Rows[customerDataGrid.CurrentCellAddress.Y].Cells["IDClmn"].Value.ToString();
                if (customerID != null)
                {
                    Int32 clientID = Int32.Parse(customerID);
                    ClientEntity client = Client.GetClient(clientID);
                    if (currentForm == 0)
                    {
                        CustomerForm form = this.Owner.ActiveMdiChild as CustomerForm;
                        form.publishClientValues(client);
                    }
                    else
                    {
                        InstalmentForm form = this.Owner.ActiveMdiChild as InstalmentForm;
                        form.publishClientValues(client);                    
                    }
                    this.Close();
                }
            }
        }
    }
}
